package com.ruoyi.yyq.service.impl;

import java.util.List;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.yyq.mapper.CarRepairReservationMapper;
import com.ruoyi.yyq.domain.CarRepairReservation;
import com.ruoyi.yyq.service.ICarRepairReservationService;

/**
 * 维修预约Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@Service
public class CarRepairReservationServiceImpl implements ICarRepairReservationService 
{
    @Autowired
    private CarRepairReservationMapper carRepairReservationMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 查询维修预约
     * 
     * @param id 维修预约主键
     * @return 维修预约
     */
    @Override
    public CarRepairReservation selectCarRepairReservationById(Long id)
    {
        return carRepairReservationMapper.selectCarRepairReservationById(id);
    }

    /**
     * 查询维修预约列表
     * 
     * @param carRepairReservation 维修预约
     * @return 维修预约
     */
    @Override
    public List<CarRepairReservation> selectCarRepairReservationList(CarRepairReservation carRepairReservation)
    {
        return carRepairReservationMapper.selectCarRepairReservationList(carRepairReservation);
    }

    /**
     * 新增维修预约
     * 
     * @param carRepairReservation 维修预约
     * @return 结果
     */
    @Override
    public int insertCarRepairReservation(CarRepairReservation carRepairReservation)
    {
        return carRepairReservationMapper.insertCarRepairReservation(carRepairReservation);
    }

    /**
     * 修改维修预约
     * 
     * @param carRepairReservation 维修预约
     * @return 结果
     */
    @Override
    public int updateCarRepairReservation(CarRepairReservation carRepairReservation)
    {
        // 业务处理
        // 获取维修状态 当维修状态为2时 给用户发送短信
        Long status = carRepairReservation.getStatus();
        if (status == 2){
            rabbitTemplate.convertAndSend("CarRepairReservation_exchange","CarRepairReservation_queue",carRepairReservation);
        }
        return carRepairReservationMapper.updateCarRepairReservation(carRepairReservation);
    }

    /**
     * 批量删除维修预约
     * 
     * @param ids 需要删除的维修预约主键
     * @return 结果
     */
    @Override
    public int deleteCarRepairReservationByIds(Long[] ids)
    {
        return carRepairReservationMapper.deleteCarRepairReservationByIds(ids);
    }

    /**
     * 删除维修预约信息
     * 
     * @param id 维修预约主键
     * @return 结果
     */
    @Override
    public int deleteCarRepairReservationById(Long id)
    {
        return carRepairReservationMapper.deleteCarRepairReservationById(id);
    }
}
